package leecode;

/**
 * 第八天
 */

public class LeetCode10 {
    //第一题
    public int fib(int n) {
        if(n<2){
            return n;
        }
        final int MOD = 1000000007;
        int a=0;
        int b=0;
        int sum=1;
        for(int i=2;i<=n;i++){
            a=b;
            b=sum;
            sum=(a+b)%MOD;
        }
        return sum;
    }
    //第二题
    public int numWays(int n) {


        final int MOD = 1000000007;
        int a=0;
        int b=0;
        int sum=1;
        for(int i=0;i<n;i++){
            a=b;
            b=sum;
            sum=(a+b)%MOD;
        }
        return sum;

    }
    //第三题，滑动窗口的应用
    public int maxProfit(int[] prices) {
        int max=0;
        for (int i=0,j=1;j<prices.length;){
            if(prices[i]<prices[j]){
                max=Math.max(prices[j]-prices[i],max);
                j++;
            }else {
                i++;
                j=i+1;
            }
        }
        return max;
    }
}
